package com.joysw.ui;

import android.os.Bundle;
import android.os.Handler;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import butterknife.ButterKnife;
import butterknife.InjectView;

import com.joysw.R;
import com.joysw.view.TitleBarView;

/**
 * 
* @Title: MainActivity.java 
* @Package com.joysw.ui 
* @Description: 订单页面
* @author LIMINGYAN  
* @date 2015年3月28日 上午7:39:14 
* @version V1.0
 */
public class MyOrderActivity extends BaseActivity implements OnClickListener,SwipeRefreshLayout.OnRefreshListener{
	
	private static final String TAG = "MyOrderActivity";
	
	@InjectView(R.id.my_order_title_bar)
	TitleBarView title_bar_view;
	//textView
	@InjectView(R.id.order_all)
	TextView mOrder_all;
	@InjectView(R.id.order_cancelled)
	TextView mOrder_cancelled;
	@InjectView(R.id.order_delivered)
	TextView mOrder_delivered;
	@InjectView(R.id.order_pending_deliver)
	TextView mOrder_pending_deliver;
	@InjectView(R.id.order_pending_payment)
	TextView mOrder_pending_payment;
	//滑动view
	@InjectView(R.id.show_order_all)
	View mShow_order_all;
	@InjectView(R.id.show_order_cancelled)
	View mShow_order_cancelled;
	@InjectView(R.id.show_order_delivered)
	View mShow_order_delivered;
	@InjectView(R.id.show_order_payment)
	View mShow_order_payment;
	@InjectView(R.id.show_order_pending_deliver)
	View mShow_order_pending_deliver;
	//列表
	@InjectView(R.id.orders_list)
	ListView mOrder_list;
	@InjectView (R.id.swipe_container)
	SwipeRefreshLayout mSwipeRefreshLayout;
	
	private String[] strs={"test1","test1","test1","test1","test1","test1"};
	 @Override
	    protected void onCreate(Bundle arg0) {
	    	// TODO Auto-generated method stub
	    	super.onCreate(arg0);
	    	setContentView(R.layout.activity_my_order);
	    	ButterKnife.inject(this);
	    	
	    	initView();
	    }

	private void initView() {
		title_bar_view.setTitleText(R.string.my_order_title);
		title_bar_view.setBtnLeft(R.drawable.ic_back, R.string.back);
		title_bar_view.setBtnLeftOnclickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				finish();
			}
		});
		mOrder_all.setOnClickListener(this);
		mOrder_cancelled.setOnClickListener(this);
		mOrder_delivered.setOnClickListener(this);
		mOrder_pending_deliver.setOnClickListener(this);
		mOrder_pending_payment.setOnClickListener(this);
		ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, strs);
		mOrder_list.setAdapter(adapter);
		mSwipeRefreshLayout.setOnRefreshListener(this);
		mSwipeRefreshLayout.setColorSchemeResources(R.color.blue); 
	}

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		switch (arg0.getId()) {
		case R.id.order_all:
			mShow_order_all.setBackgroundColor(getResources().getColor(R.color.common_title));
			mShow_order_cancelled.setBackgroundColor(getResources().getColor(R.color.bg_Gray));
			mShow_order_delivered.setBackgroundColor(getResources().getColor(R.color.bg_Gray));
			mShow_order_payment.setBackgroundColor(getResources().getColor(R.color.bg_Gray));
			mShow_order_pending_deliver.setBackgroundColor(getResources().getColor(R.color.bg_Gray));
			break;
		case R.id.order_cancelled:
			mShow_order_all.setBackgroundColor(getResources().getColor(R.color.bg_Gray));
			mShow_order_cancelled.setBackgroundColor(getResources().getColor(R.color.common_title));
			mShow_order_delivered.setBackgroundColor(getResources().getColor(R.color.bg_Gray));
			mShow_order_payment.setBackgroundColor(getResources().getColor(R.color.bg_Gray));
			mShow_order_pending_deliver.setBackgroundColor(getResources().getColor(R.color.bg_Gray));
			break;
		case R.id.order_delivered:
			mShow_order_all.setBackgroundColor(getResources().getColor(R.color.bg_Gray));
			mShow_order_cancelled.setBackgroundColor(getResources().getColor(R.color.bg_Gray));
			mShow_order_delivered.setBackgroundColor(getResources().getColor(R.color.common_title));
			mShow_order_payment.setBackgroundColor(getResources().getColor(R.color.bg_Gray));
			mShow_order_pending_deliver.setBackgroundColor(getResources().getColor(R.color.bg_Gray));
			break;
		case R.id.order_pending_deliver:
			mShow_order_all.setBackgroundColor(getResources().getColor(R.color.bg_Gray));
			mShow_order_cancelled.setBackgroundColor(getResources().getColor(R.color.bg_Gray));
			mShow_order_delivered.setBackgroundColor(getResources().getColor(R.color.bg_Gray));
			mShow_order_payment.setBackgroundColor(getResources().getColor(R.color.bg_Gray));
			mShow_order_pending_deliver.setBackgroundColor(getResources().getColor(R.color.common_title));
			break;
		case R.id.order_pending_payment:
			mShow_order_all.setBackgroundColor(getResources().getColor(R.color.bg_Gray));
			mShow_order_cancelled.setBackgroundColor(getResources().getColor(R.color.bg_Gray));
			mShow_order_delivered.setBackgroundColor(getResources().getColor(R.color.bg_Gray));
			mShow_order_payment.setBackgroundColor(getResources().getColor(R.color.common_title));
			mShow_order_pending_deliver.setBackgroundColor(getResources().getColor(R.color.bg_Gray));
			break;
		}
	}

	@Override
	public void onRefresh() {
		// TODO Auto-generated method stub
		new Handler().postDelayed(new Runnable() {
			@Override
			public void run() {
				mSwipeRefreshLayout.setRefreshing(false);
			}
		}, 5000);
	}

}
